package br.com.uniban.util;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.com.uniban.dao.AdministradorRemote;
import br.com.uniban.dao.ProvaRemote;
import br.com.uniban.dao.ProvaRespRemote;
import br.com.uniban.dao.QuestaoRemote;
import br.com.uniban.dao.UsuarioRemote;
import br.com.uniban.mdb.SendEmailRemote;

public class SessionBeanFactory {
	
	public static QuestaoRemote getInstanceQuestaoRemote() throws Exception{
		return (QuestaoRemote) getInitialContext().lookup(QuestaoRemote.JNDI);
	}
	
	public static AdministradorRemote getInstanceAdministradorRemote() throws Exception{
		return (AdministradorRemote) getInitialContext().lookup(AdministradorRemote.JNDI);
	}
	
	public static ProvaRemote getInstanceProvaRemote() throws Exception{
		return (ProvaRemote) getInitialContext().lookup(ProvaRemote.JNDI);
	}
	
	public static ProvaRespRemote getInstanceProvaRespRemote() throws Exception{
		return (ProvaRespRemote) getInitialContext().lookup(ProvaRespRemote.JNDI_PROVA_RESP);
	}
	
	public static UsuarioRemote getInstanceUsuarioRemote() throws Exception{
		return (UsuarioRemote) getInitialContext().lookup(UsuarioRemote.JNDI);
	}
	public static SendEmailRemote getInstanceSendEmailRemote() throws NamingException {
		return (SendEmailRemote) getInitialContext().lookup(SendEmailRemote.JNDI);
	}
		
	private static InitialContext getInitialContext() throws NamingException {
		Properties env = new Properties();
		env.put(Context.SECURITY_PRINCIPAL, "guest");
		env.put(Context.SECURITY_CREDENTIALS, "guest");
		env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
		env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
		return new InitialContext(env);
	}
}
